package com.activenetwork.util.grid.condition;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class ContainsCondition implements Condition {
	
	private int column;
	private String value;
	
	public void setColumn(int column) {
		this.column = column;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	public int getColumn() {
		return column;
	}
	
	public String getValue() {
		return value;
	}
	/**
	 * Empty constructor
	 */
	public ContainsCondition(){
		this.column = -1;
		this.value = null;
	}
	/**
	 * Direct constructor
	 * @param column
	 * @param value
	 */
	public ContainsCondition(int column, String value){
		 this.column = column;
	     this.value = value;
	}
	
	@Override
	public boolean matchs(WebElement row) {
		String tdValue = row.findElement(By.xpath("./td[" + column + "]")).getText().trim();
		if(StringUtils.containsIgnoreCase(tdValue, this.value)){
			return true;
		}else{
			return false;
		}
	}
	
}
